package com.loctek.importexport.mvp.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.loctek.importexport.R;
import com.loctek.importexport.base.BaseFragment;
import com.loctek.importexport.base.BasePresenter;
import com.loctek.importexport.base.BaseView;
import com.loctek.importexport.base.NetworkImageHolderView;
import com.loctek.importexport.bean.testpaperSearchByAjaxResponse;
import com.loctek.importexport.bean.testpaperStartIsOkResponse;
import com.loctek.importexport.mvp.acitvity.LoginActivity;
import com.loctek.importexport.mvp.acitvity.OutHousingActivity;
import com.loctek.importexport.mvp.acitvity.ScanningProductActivity;
import com.loctek.importexport.mvp.acitvity.TransferLibraryActivity;
import com.loctek.importexport.mvp.acitvity.WareHousingActivity;
import com.loctek.importexport.util.ScreenUtil;
import com.trello.rxlifecycle.LifecycleTransformer;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * ━━━━━━神兽出没━━━━━━
 * 　　　┏┓　　　┏┓
 * 　　┏┛┻━━━┛┻┓
 * 　　┃　　　　　　　┃
 * 　　┃　　　━　　　┃
 * 　　┃　┳┛　┗┳　┃
 * 　　┃　　　　　　　┃
 * 　　┃　　　┻　　　┃
 * 　　┃　　　　　　　┃
 * 　　┗━┓　　　┏━┛
 * 　　　　┃　　　┃  神兽保佑
 * 　　　　┃　　　┃  代码无bug
 * 　　　　┃　　　┗━━━┓
 * 　　　　┃　　　　　　　┣┓
 * 　　　　┃　　　　　　　┏┛
 * 　　　　┗┓┓┏━┳┓┏┛
 * 　　　　　┃┫┫　┃┫┫
 * 　　　　　┗┻┛　┗┻┛
 * ━━━━━━感觉萌萌哒━━━━━━
 * <p>
 * 作者：司海林
 * 邮箱：sihailin@sina.cn
 * 时间：2017/9/11
 * 描述：
 */
public class HomeFragment extends BaseFragment<BaseView, BasePresenter<BaseView>> implements View.OnClickListener {
    final Integer[] resImages = {R.mipmap.banner_1, R.mipmap.banner_2, R.mipmap.banner_3, R.mipmap.banner_4, R.mipmap.banner_5};
    @BindView(R.id.convenientBanner)
    ConvenientBanner convenientBanner;
    Unbinder unbinder;
    @BindView(R.id.appbar_01)
    AppBarLayout appbar01;
    @BindView(R.id.ware_housing_ll)
    LinearLayout wareHousingLl;
    @BindView(R.id.main_content)
    LinearLayout mainContent;
    @BindView(R.id.out_housing_ll)
    LinearLayout outHousingLl;
    @BindView(R.id.llyt_exit_btn)
    LinearLayout llytExitBtn;
    @BindView(R.id.llyt_scanning)
    LinearLayout llytScanning;
    @BindView(R.id.llyt_transfer_library)
    LinearLayout llytTransferLibrary;


    @Override
    public BasePresenter createPresenter() {
        return new BasePresenter(getApp());
    }

    @Override
    public <T> LifecycleTransformer<T> bindToLife() {
        return null;
    }

    @Override
    public int getRootViewId() {
        return R.layout.fragment_home;
    }


    @Override
    public void initUI() {

        convenientBanner.setPages(new CBViewHolderCreator<NetworkImageHolderView>() {
            @Override
            public NetworkImageHolderView createHolder() {
                return new NetworkImageHolderView(ScreenUtil.screenWidth, ScreenUtil.dip2px(150));
            }
        }, Arrays.asList(resImages))
                .setPageIndicator(new int[]{R.mipmap.banner_nor_tag, R.mipmap.banner_sel_tag})
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL);

        wareHousingLl.setOnClickListener(this);
        outHousingLl.setOnClickListener(this);
        llytExitBtn.setOnClickListener(this);
        llytScanning.setOnClickListener(this);

        llytTransferLibrary.setOnClickListener(this);
    }


    @Override
    public void initData() {
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llyt_scanning://扫码
                Intent intent1 = new Intent(getActivity(), ScanningProductActivity.class);
                startActivity(intent1);
                break;
            case R.id.ware_housing_ll://入库
                Intent intent = new Intent(getActivity(), WareHousingActivity.class);
                startActivity(intent);
                break;
            case R.id.out_housing_ll://出库
                Intent intent4 = new Intent(getActivity(), OutHousingActivity.class);
                startActivity(intent4);
                break;
            case R.id.llyt_transfer_library://移库
                Intent intent3 = new Intent(getActivity(), TransferLibraryActivity.class);
                startActivity(intent3);
                break;

            case R.id.llyt_exit_btn://退出
                Intent intent5 = new Intent(getActivity(), LoginActivity.class);
                startActivity(intent5);
                finish();
                break;
        }
    }


    @Override
    public void onResume() {
        super.onResume();
        //开始自动翻页
        convenientBanner.startTurning(3000);
    }

    @Override
    public void onPause() {
        super.onPause();
        //停止翻页
        convenientBanner.stopTurning();
    }

}
